import matplotlib.pyplot as plt
from datetime import datetime
import csv

filename = '../file/death_valley_2014.csv'
with open(filename) as file:
    reader = csv.reader(file)
    header_row = next(reader)

    for index,column_header in enumerate(header_row):
        print(index,column_header)

    # 将日期和最高温，最低温分别存储在一个列表中
    dates = []
    highs = []
    lows = []

    for row in reader:
        try:
            date = datetime.strptime(row[0], '%Y-%m-%d')
            high = int(row[8])
            low = int(row[9])
        except:
            property("数据有误")
        else:
            dates.append(date)
            highs.append(high)
            lows.append(low)

    # 根据数据绘制图形
    fig = plt.figure(dpi=128,figsize=(10,6))
    plt.plot(dates,highs,c='red')
    plt.plot(dates,lows,c='blue')

    # 给指定区域内着色
    plt.fill_between(dates,highs,lows,facecolor='blue',alpha=0.3)

    # 设置图形的信息
    plt.title('The highest daily temperature in July 2014 valley',fontsize=16)
    plt.xlabel('',fontsize=16)

    # x轴文字倾斜
    fig.autofmt_xdate()

    plt.ylabel("Humidity",fontsize=16)
    plt.tick_params(axis="both",which='major',labelsize=16)

    plt.show()